//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if !defined (_TOUCH_H_)
#define _TOUCH_H_

#include "../drvlib/rbuf.h"

#define _NEED_EXCHANGE

#define SYNCHRONIZATION  0
#define ASYNCHRONISM     1
#define RBUF_LEN         20

/* pen state */
#define TP_PEN_DOWN     1
#define TP_PEN_UP       0
#define TP_PEN_MOVE     2
#define TP_PEN_PUSH     3

/* virtual key state*/

/* virtual key define (MakeCode)*/
#define vkey1   0x2
#define vkey2   0x3
#define vkey3   0x4
#define vkey4   0x5
#define vkey5   0x6

#define LCD_WIDTH                   240
#define LCD_HEIGHT                  320

// ASCII
#define STX		0x02
#define ETX		0x03
#define EOT		0x04
#define ENQ		0x05
#define BS		0x08
#define CR		0x0D
#define LF		0x0A
#define DLE		0x10
#define ETB		0x17
#define SPACE   0x20
#define BLANK   0X7f

// colour
#define WHITE       0xffff
#define BLACK       0x0000
#define RED         0xf800
#define GREEN       0x07e0
#define BLUE        0x001f
#define YELLOW      RED | GREEN

typedef struct _touch_data {
    int dir;
    int x;
    int y ;
    int reserve;
}TOUCH_DATA;

/* pointer data struct */
typedef struct _pointer_st{
    UINT dir;            /* 0x40 - up, 0x41 - down, 0x42 - move */
    UINT x;                /* point x after revising */
    UINT y;                /* point y after revising */
    int _x;                /* point x before revising  */
    int _y;                /* point y before revising */
    int timestamp;        /* click timestamp */
} MOUSE_ST;

class CPen : public Driver {
public:
    CARAPI Read(
        /* [in] */ UINT64 u64Offset,
        /* [in] */ UINT uNumberOfBytesToRead,
        /* [out] */ EzByteBuf ebbData,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ UINT64 u64Offset,
        /* [in] */ EzByteBuf ebbData,
        /* [out] */ UINT * puNumberOfBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ INT nControlCode,
        /* [in] */ EzByteBuf ebbInData,
        /* [out] */ EzByteBuf ebbOutData,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();

    ECode Initialize();

public :
        DzMutex m_Lock;
        MOUSE_ST pt;
        int reviseX1, reviseX2, reviseY1, reviseY2;
};

#endif

